//假子弹基础类(紧紧用来演示射击)
//1.生成子弹图片
//2.更换子弹的刚体
//3.负责子弹的移动，或者给力
//4.负责子弹的停止

module py2Obj {


	export class fakeBullet extends basicObj {
		//保存外部的物理世界
		private time: egret.Timer;
		private bulletType: any;
		private label: TextField;
		public isRun = false;

		public pointList: egret.Point[] = [];
		//public label: egret.TextField = new egret.TextField();
		public constructor(world: any, gamePanle: any, romveSkins: any) {
			super(world, gamePanle, romveSkins);
			this.objkind = 301;

		}
		public init() {
			super.init();

		}
 public a:any;//新手引导
 public b:any; 
 public cishu:number=0;
		public send(x, y, forcex, forcey) {
			this.m_body.type = 1;
			this.isRun = true;
			this.m_body.velocity = [0, 0];
			this.m_body.damping = 0;
			this.setPostion(x, y);
			this.setForce(forcex, forcey);
			
			this.a=forcex;//新手引导
			this.b=forcey;//新手引导
			if(this.cishu==0&&tishi<9){//新手引导
               this.cishu=1;
			 var timer: egret.Timer = new egret.Timer(500, 1);
                timer.addEventListener(egret.TimerEvent.TIMER_COMPLETE, this.timerCom, this);
                timer.start();
		}//新手引导
	}
		public timerCom()//新手引导
		{
			this.setForce(this.a*-1,this.b*-1);
			 GameControl.GameControlSole.upgradeNumber2=2;
			 GameControl.GameControlSole.UpgradeTishi();
		}//新手引导
		public createMyRigidbody(): p2.Body {



			// this.label.text = "0";
			// this.label.height = 100;
			// this.label.width = 200;
			// this.label.size = 28;
			// this.label.textColor = 0xFF0000;
			// this.label.x = this.m_body.position[0];
			// this.label.y = this.m_body.position[1];

			var world: P2World = this.m_world;
			var skin: MImage = this.createSkin("ball_png");
			var body: p2.Body = world.createCircleBodyShape(13);
			body.userData.skin = skin;
			body.userData.data = this;
			body.mass = 0;//质量设置为0，就可以按规定方向发射，等发生碰撞之后再给球质量
			//body.gravityScale=0;
			var shape = body.shapes[0];
			shape.collisionGroup = 2;//010与001为0，010与110为1
			// shape.collisionMask=2;
			// trace(shape.collisionGroup,shape.collisionMask)

			// var skin1: MImage = this.createSkin(this.label.text);
			// var body1: p2.Body = world.createCircleBodyShape(10);
			// body1.userData.skin = skin1;
			// body1.userData.data = this;
			// body1.mass = 0;//质量设置为0，就可以按规定方向发射，等发生碰撞之后再给球质量
			// body.gravityScale = 0;
			// var shape1 = body1.shapes[0];
			// shape.collisionGroup = 2;//010与001为0，010与110为1
			// shape1.collisionMask = 6;
			// this.label.x = this.m_body.position[0];
			// this.label.y = this.m_body.position[1];
			// shape.collisionMask=2;
			// trace(shape.collisionGroup,shape.collisionMask)


			return body;

		}
		// protected createText(x: number = 0, y: number = 0, s: string = ""): TextField {
		// 	var text: TextField = (new Label).textField;
		// 	text.x = x; text.y = y; text.text = s;
		// 	this.addChild(text);
		// 	return text;
		// }
		private createFixedBullet() {

		}

		public runEnd() {

			var bullet = new py2Obj.basicBullet(this.m_world, this.m_gamePanle, this.m_removeSkins);
			bullet.init();
			bullet.setPostion(this.m_body.position[0], this.m_body.position[1]);
			this.m_gamePanle.doMaterial(bullet.getBody());
			// bullet.setForce(this.vec.x, this.vec.y);
			// this.setChildIndex(this.gun, this.numChildren - 1);
			this.isRun = false;
			this.recyle1();
			return bullet;
		}
		public runEnd1() {
			this.m_body.type = 3;//该死的 终于找到你
			this.isRun = true;
		}
		public recyle1() {
			this.m_body.velocity = [0, 0];
			this.m_body.type = 2;
			this.setPostion(-100, -100);
			this.isRun = false;
		}
		public recyle() {
			this.isRun = true;
			this.m_body.type = 2;
			this.time = new egret.Timer(50, 1);
			this.time.start();//开始计时
			this.time.addEventListener(egret.TimerEvent.TIMER, this.jishi, this);
		}
		public jishi() {
			this.isRun = true;
			this.m_body.type = 1;
		}
		public strikeRecyle() {
			this.m_body.type = 3;
		}
		/**
		 * Body.KINEMATIC = 4;
		 * Body.STATIC = 2;
		 * Body.DYNAMIC = 1;
		 */
		public getCollision(otherBody: basicObj) {
			if (otherBody.objkind == 100) {
				return;
			}
			if (otherBody.objkind == 500) {
				return;
			}
			if(otherBody.objkind == 600)
			{
               return;
			}
		}
	}
}